package de.uni.muenster.idw2.threads;

import de.uni.muenster.idw2.data.Building;
import de.uni.muenster.idw2.graphextraction.Graphextractor;
import android.app.Activity;
import android.os.AsyncTask;
import android.util.Log;

public class GraphExtractorAsyncThread extends AsyncTask<Void, Void, Void>{

	private Activity act;
	private Building building;

	public GraphExtractorAsyncThread(Activity act, Building building){
		this.act = act;
		this.building = building;
		
		
	}
	
	@Override
	protected void onPreExecute() {
		building.setLoading(true);
		super.onPreExecute();
	}
	
	
	
	
	@Override
	protected Void doInBackground(Void... params) {
		// hier das network extracten
			long startTime = System.currentTimeMillis();
			Log.v("wichtig", "beginn graph extraction");
			
			Graphextractor graphEx = new Graphextractor(building);
	    	graphEx.extractNetwork();
	    	
	    	building.setRoutingNetworkVertices(graphEx.getVertices());
	    	building.setRoutingNetworkEdges(graphEx.getEdges());

	    	long exTime = System.currentTimeMillis()- startTime;
	    	Log.v("wichtig", "graph extraction succeded in " + exTime);

		
		
		return null;
	}
	
	@Override
	protected void onPostExecute(Void result) {
		super.onPostExecute(result);
		building.setLoadingCompleted(true);
	}

	
}
